<extend name="Public/base" />

<block name="style">
 <link href="__CSS__/freeshipping.min.css?v={:C('CURRENT_FILE_VERSION')}" rel="stylesheet" />
<style>
    .page-content{padding:0px 10px 15px;}
    .search_pannl_div .single-col label{width:75px;}
</style>

 <link rel="stylesheet" href="__PUBLIC__/Admin/css/dropload.css">
          <style>
    {
        margin: 0;
        padding:0;
        -webkit-tap-highlight-color:rgba(0,0,0,0);
        -webkit-text-size-adjust:none;
    }
    html{
        font-size:10px;
    }
    body{
        background-color: #f5f5f5;
    /*    font-size: 1.2em;*/
    }
    .outer{
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        display: -webkit-box;
        display: -webkit-flex;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-direction:column;
        -webkit-box-orient:vertical;
        box-orient:vertical;
        -webkit-flex-direction:column;
        flex-direction:column;
    }
    .header{
        position: relative;
        height: 44px;
        line-height: 44px;
        border-bottom: 1px solid #ccc;
        background-color: #eee;
    }
    .header h1{
        text-align: center;
        font-size: 2rem;
        font-weight: normal;
    }
    .header .btn{
        position: absolute;
        right: 0;
        top: 0;
        width: 4em;
        height: 100%;
        text-align: center;
        color: #06c;
        font-size: 1.4rem;
        background-color: #ccc;
    }
    .header .btn:active{
        background-color: #aaa;
        color: #fff;
    }
    .inner{
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        -ms-flex: 1;
        flex: 1;
        background-color: #fff;
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
    }
    .inner .item{
        display: -webkit-box;
        display: -webkit-flex;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-align:center;
        -webkit-box-align:center;
        box-align:center;
        -webkit-align-items:center;
        align-items:center;
        padding:3.125%;
        border-bottom: 1px solid #ddd;
        color: #333;
        text-decoration: none;
    }
    .inner .item img{
        display: block;
        width: 40px;
        height: 40px;
        border:1px solid #ddd;
    }
    .inner .item h3{
        display: block;
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        -ms-flex: 1;
        flex: 1;
        width: 100%;
        max-height: 40px;
        overflow: hidden;
        line-height: 20px;
        margin: 0 10px;
        font-size: 1.2rem;
    }
    .inner .item .date{
        display: block;
        height: 20px;
        line-height: 20px;
        color: #999;
    }
    .opacity{
        -webkit-animation: opacity 0.5s linear;
        animation: opacity 0.5s linear;
    }
    @-webkit-keyframes opacity {
        0% {
            opacity:0;
        }
        100% {
            opacity:1;
        }
    }
    @keyframes opacity {
        0% {
            opacity:0;
        }
        100% {
            opacity:1;
        }
    }
  .weui_media_text .weui_media_title{
            font-size: 15px;
        }

        .shipping_content_table{ 
            font-size: 12px;
            line-height: 1.6;
            border: 1px solid #ddd;
            border-collapse: collapse;
            width: 100%;
        }
        input.checkbox{
            vertical-align: middle;
            margin-right: 4px;
        }
        body {
            -webkit-text-size-adjust: none;
            padding: 0;
            font-family: Helvetica,'é»‘ä½“',Verdana,Arial,Helvetica,sans-serif;
            font-size: 1em;
            background: #eee;
            padding: 0;
            min-width: 320px;
            max-width: 640px;
            margin: 0 auto;
            overflow-x: hidden;
        }
        button#submit {
            width: 100px;
            height: 28px;
            margin-left: 10px;
            display: block;
            text-align: center;
            background: #ddd;
            border: 0 none;
            cursor: pointer;
            margin-bottom: 10px;
        }
        .shipping_content_table td{
            text-align: center;
        }
        .shipping_content_table td, .shipping_content_table th{
            border:1px solid #ddd;
            font-size: 12px;
        }




.gaikuang{ width:10%}
.weui_media_title{ font-size:13px !important;; color:#c00;}
.module_title{ font-size:16px !important;}
button#submit{ background:#5cac25 !important; color:#ffffff;}
.weui_media_box{ padding:15px 15px 10px 15px;}

button#submit{ float:left;}
.txzl{ float:right; line-height:28px;    width: 100px;
    height: 28px;
    margin-right: 10px;
    display: block;
    text-align: center;
    border: 0 none;
    cursor: pointer;
  font-size:12px;
    margin-bottom: 10px;
      background: #5cac25 !important;
    color: #ffffff; }
/*-----cg4tanchu-----*/
.sg_wszl{ width:100%; height:100%; background-color:#000000; background:rgba(0,0,0,.7);position:fixed; z-index:888; top:0; display:none;
 /**  格式，filer: blur(模糊半径)
     *  模糊半径，取值范围0~Npx，0为无效果
     */
/*
 -webkit-filter: blur(10px);
     -moz-filter: blur(10px);
     -o-filter: blur(10px);
     -ms-filter: blur(10px);
     filter: blur(10px);*/}
 .sg_nrk{ width:90%;  position:fixed;  background-color:#FFFFFF; top:-500px; z-index:999; left:50%; margin-left:-44%; padding-bottom:18px;   }
 .sg_nrk_waz{ width:100%;height:38px; background-color:#5cad25; line-height:38px; color:#FFFFFF; font-size:14px; display:block; padding-left:20px; margin-bottom:38px; position:relative;box-sizing:border-box;
-moz-box-sizing:border-box; /* Firefox */
-webkit-box-sizing:border-box; /* Safari */}
 .sg_nrk_waz span{ display:block; position:absolute; width:38px; height:38px; right:0; top:0; cursor:pointer;}
  .sg_nrk_waz span img{ padding:13px;}
 .sg_nrk_waz_xia1{ width:100%; height:32px; display:block;  margin-bottom:8px; }
 .sg_nrk_waz_xia1_wz1{ width:22%; height:32px; line-height:32px; display:block; text-align:right; float:left; font-size:12px !important; color:#000000; padding-right:14px; position:relative;}
 .sg_nrk_waz_xia1_wz1 span{ color:#FF0000; position:absolute; top:4px;}
 .sg_nrk_waz_xia1_wz2{ float:left; width:60%; height:30px; line-height:30px; border:1px solid #cccccc; padding:0 4px;border-radius:2px;
 -moz-box-shadow:0 3px 3px #e5e5e5 inset;              /* For Firefox3.6+ */
-webkit-box-shadow:0 3px 3px #e5e5e5 inset;           /* For Chrome5+, Safari5+ */
  box-shadow:0 3px 3px #e5e5e5 inset;                   /* For Latest Opera */ }

  .lxrcc{ width:138px;}
  .lxrccwz{ width:74px; text-align:center; padding:0;}
  .lxrcc2{ width:370px;}
  .sg_nrk_ccx{ width:186px; height:35px; display:block; margin:auto;}
  .sg_nrk_ccx_a1, .sg_nrk_ccx_a2{ width:90px; height:35px; display:block; line-height:35px; display:block; float:left; font-size:14px; text-align:center; margin-top:20px;}
.sg_nrk_ccx_a1{ margin-right:6px; background-color:#e3e3e5; color:#666666;}
.sg_nrk_ccx_a2{ background-color:#5cad25; color:#FFFFFF;}


 .sg_nrk_waz_xia1_wz2:focus,textarea:focus{border:#4D90FE solid 1px;transition: all .3s ease-in-out;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
outline:none;box-shadow: 0 0 5px rgba(81, 203, 238, 1);
-webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 1);
-moz-box-shadow: 0 0 5px rgba(81, 203, 238, 1);}
</style>
</block>

<block name="body">
        
    <div class="weui_panel weui_panel_access">
        <div class="weui_panel_hd module_title">采购单商品列表</div>
        <div class="weui_panel_bd">

           
                    <!--添加一条灰色背景的div-->
                    <div class="line_bg"></div>
                    <div class="weui_media_box weui_media_text ">
                        <h4 class="weui_media_title">{$list['purchaseame']}：
                      （截至时间：{$list['lasttime']}）
                        </h4> 
                        <p class="weui_media_desc">
                            
                         </p><div class="inner">
                         <div class="lists">
                         <div class="lists">
                    <table class="centre shipping_content_table" > 
                      <tr><th class="gaikuang"></th><th>商品名</th><th>数量</th><th>目标价</th></tr>
                             <volist name="content" id="g">
                                <tr>
                                <td class="gaikuang"><input type="checkbox" name="checkbox{$key}"  field='"listid":"{$g.listid}","purchaseid":"{$g.purchaseid}","goodsid":"{$g.goodsid}","goodsname":"{$g.goodsname}","price":"{$g.price}","number":"{$g.number}","unit":"{$g.unit}"'  value="{$g.goodsid}"  purchaseid="{$vo.purchaseid}"  class="checkbox" name="checkbox_{$vo.purchaseid}" /></td>
                                    <td class="td_name">{$g.goodsname}</td>
                                    <td class="td_content">
                                        <span class="number">{$g.number}</span>
                                      </td>  
                                      <td class="td_content">  
                                         <span class="price">{$g.price}</span>

                                    </td>
                                </tr>
                                </volist> 
                    </table>
                      </div>
                      </div>
 
                           
                        </p>
                    </div>
          
              <button id="submit">填写报价单</button>
               <div class="txzl" id="activator">完善供应商资料</div>
     
        </div>
    </div>

<div class="sg_wszl"></div>
  <div class="sg_nrk">
    <div class="sg_nrk_waz" >完善资料<span class="fzccx"><img src="/images/xcc.png"  /></span></div>
          <div class="sg_nrk_waz_xia1">
      <div class="sg_nrk_waz_xia1_wz1" isactive="{$supplier_list.isactive}" id="data_isactive" >资料状态</div>
    
      <if condition="$supplier_list.isactive eq '0'">
        <p class="sg_nrk_waz_xia1_wz3" style="color:red;">您的资料正在审核中,请耐心等待......</p>
      <elseif condition="$supplier_list.isactive eq 1"/>
         <p class="sg_nrk_waz_xia1_wz3" style="color:red;">您的资料已经审核成功！</p>
      <elseif condition="$supplier_list.isactive eq 2"/>
         <p class="sg_nrk_waz_xia1_wz3" style="color:red;">您的资料审核不合格，请修改资料！</p>
     </if>
     </div>
  <if condition="$supplier_list.isactive eq '1'" >
                 <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">公司名称<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="companyname" readonly="readonly" value="{$supplier_list.companyname}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">ABN<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="abncode"readonly="readonly" value="{$supplier_list.abncode}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">联系人<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="linkname" readonly="readonly" value="{$supplier_list.linkname}" />

             <div class="sg_nrk_waz_xia1_wz1  ">联系方式<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="moblie" readonly="readonly" value="{$supplier_list.moblie}" />
           </div>
           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">地址<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="address" readonly="readonly" value="{$supplier_list.address }" />
           </div>
           <div class="sg_nrk_ccx">
           <p class="sg_nrk_waz_xia1_wz3" style="color:red;">如果需要修改供应商资料，请联系客服！</p>

           </div>
    <else />
                  <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">公司名称<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="companyname"  value="{$supplier_list.companyname}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">ABN<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="abncode" value="{$supplier_list.abncode}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">联系人<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="linkname" value="{$supplier_list.linkname}" />

             <div class="sg_nrk_waz_xia1_wz1  ">联系方式<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="moblie" value="{$supplier_list.moblie}" />
           </div>
           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">地址<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="address" value="{$supplier_list.address }" />
           </div>
          <div class="sg_nrk_ccx">
             <div class="sg_nrk_ccx_a1" onclick="close_win()">取消</div>
              <div class="sg_nrk_ccx_a2" onclick="sub_supplier()">保存</div>
             
          </div>
      </if>
  
  

  

 </div>

  
  
</block>

<block name="script">
 <script src="__PUBLIC__/Admin/js/dropload.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/js/json2.js"></script>
<script type="text/javascript">
  //定义cookiename
var cookiename="goods_{$purchaseid}";
var purchaseid = "{$purchaseid}";
$('#submit').bind('click',button_offer_goods);
$('input[type="checkbox"]').unbind("click",setgoodincookie);
$('input[type="checkbox"]').bind("click",setgoodincookie);
   listinit();//初始化页面 
     var pageNow =2;
 $(function(){     
    var dropload = $('.inner').dropload({
        domUp : {
            domClass   : 'dropload-up',
            domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',
            domUpdate  : '<div class="dropload-update">↑释放更新</div>',
            domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
        },
        domDown : {
            domClass   : 'dropload-down',
            domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
          /*  domRefresh : "",*/
            domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            /*domLoad : "",*/
            domNoData  : '<div class="dropload-noData">暂无数据</div>'
         /*   domNoData :""*/
        },
                loadUpFn : function(me){
            $.ajax({
                type: 'POST',
              /*  url: '{:U("Offer/index")}',*/
                      url: "{:U('Offer/offer_details')}",
                      data:{purchaseid:purchaseid},
               /* dataType: 'json',*/
               success: function(data){
                 if(data == ""){
                       dropload.lock();
                       dropload.noData();
                       dropload.resetload();
                    //alert('没有数据啦!');
                }else{
                       var data = '<tr><th class="gaikuang"></th><th>商品名</th><th>数量</th><th>目标价</th></tr>'+data;
                        $('.shipping_content_table').html(data);
                        // 每次数据加载完，必须重置
                        dropload.resetload();
                        dropload.unlock();
                          listinit();//初始化页面 
                          
                        $('input[type="checkbox"]').unbind("click",setgoodincookie);
                        $('input[type="checkbox"]').bind("click",setgoodincookie);
                         pageNow =2;
                           
                    }
                },
                error: function(xhr, type){
                  
                    // 即使加载出错，也得重置
                       dropload.resetload();
                        dropload.unlock();
                }

            });
        },
        scrollArea : window,
        loadDownFn : function(me){
         
            $.ajax({
                type: 'POST',
                url: "{:U('Offer/offer_details')}",
               /* dataType: 'json',*/
               data:{pageNow:pageNow,purchaseid:purchaseid},
                success: function(data){
                if(data == ""){
                       $('.dropload-down').show();
                        //dropload.lock();
                        dropload.noData();
                       dropload.resetload();
                       setTimeout(function(){
                          $('.dropload-down').hide();
                       },1000);
            
                }else{
                  
                        $('.shipping_content_table').append(data);
                         listinit();//初始化页面 
                        dropload.resetload();
                       
                        $('input[type="checkbox"]').unbind("click",setgoodincookie);
                        $('input[type="checkbox"]').bind("click",setgoodincookie);
                        pageNow ++;
              /*          if(data.length < 20 ){
                            dropload.lock();
                            dropload.noData();
                        }*/
              

                  }
                },
                error: function(xhr, type){
                  dropload.resetload();
                    alert('Ajax error!');
                    // 即使加载出错，也得重置
                   dropload.resetload();
                }
            });
        }
    });

     //$('input[type="checkbox"]').bind("click",setgoodincookie);
 
    


  
 }); 

//点击填写报价单
     function button_offer_goods(){
    //先判断是否有 供应商资料
    var data_isactive =$('#data_isactive').attr('isactive');
     if(data_isactive == ''){
      $("#activator").trigger("click");
      return;
    }

    if(data_isactive == 2){
     alert('亲，供应商资料不合格请继续完善！');
      return;
    }
    if(data_isactive == 0){
         alert('亲，请等待供应商资料审核通过，如果有特殊情况请联系客服！');
       return;
    }

    var _list=getCookie(cookiename);
    if(_list==""){
        alert('亲，请先选择商品吧！');
      return;
    }   
    //alert(purchaseid);
    location.href = "{:U('Offer/offertab',array('purchaseid'=>$purchaseid))}";
  } 
//提交供应商资料
function sub_supplier(){
  var companyname = $('input[name=companyname]').val();
  var abncode = $('input[name=abncode]').val();
  var linkname = $('input[name=linkname]').val();
  var moblie = $('input[name=moblie]').val();
  var address = $('input[name=address]').val();
      if($.trim(companyname) =="" || $.trim(abncode) =="" || $.trim(linkname) =="" || $.trim(moblie) =="" || $.trim(address) ==""){
    alert('资料完善不能为空！');
        return;
      }
      var re = /(^0\d{9}$)/;
      if(!re.test(moblie)){
        alert('请填写澳洲号码！');
        return;
      }
        $.ajax({
         'url': "{:U('Offer/set_supplier')}",
         'data': {companyname:companyname,
                   abncode:abncode,
                   linkname:linkname,
                   moblie:moblie,
                   address:address
                 },
         'dataType': 'json',
         'type': 'POST',
        success: function (data) {
        if(data.staute =="success"){

              alert(data.msg);
              close_win();
              return;
        }
        if(data.staute =="error"){
                 alert(data.msg);
              return;
        }  

       }, error: function (err) { 
                   //art.dialog({title:'温馨提示',content: err.responseText, ok: function () {this.close();return false;},okval:'确定'});
       },complete: function () {

       }
               });    


}

 //初始化页面设置存在选中的商品信息
 function listinit(){
    debugger;
   var _list=getCookie(cookiename);
   if(_list==""){return;}
   var ojson=JSON.parse(_list);
   
   $('input[type="checkbox"]').each(function(){
    var tmp= $(this).val();
    var _isflg=isExist(ojson,tmp);
    if(_isflg){
      $(this).prop("checked",_isflg);
    }
   }); 
 }
 
 
 //判断json数据中是否存在商品编号id
 function isExist(ary,val){
    var flg=false;
    if(ary==null || ary.length==0)return flg;
    for(var i=0;i<ary.length;i++){
      if(ary[i]['goodsid']==val){
        flg=true;
        break;
      }
    }
    return flg;
 }
 
 
 //勾选时执行数据的清理以及写入
 function setgoodincookie()
 {
  debugger;
  var flg= $(this).is(":checked");
  var _json=[],ojson=[],json=[];   
  var _tmv="{"+$(this).attr("field")+"}";
  var _json=JSON.parse(_tmv); 
  if(!_json)return;
  
  //获取cookie值
  var _list=getCookie(cookiename);
  if(_list!=""){
    ojson=JSON.parse(_list);
  } 
  
  //从cookie中获取的值哪些需要删除，哪些需要更新 
  for(var i=0;i<ojson.length;i++){ 
    //相等处理
    if(ojson[i]['goodsid']==_json['goodsid']){ 
       if(flg){json.push(_json);}  //勾选，就更新这个记录
      }  
    else{
      json.push(ojson[i]);  //不相等添加
    }
    } 
  
  var bl=isExist(ojson,_json['goodsid']);
  //如果是勾选并且是不存在cookie记录新时，增加
  if(!bl && flg){json.push(_json);}
  
  //考虑重复记录的清理。 
  
    setCookie(cookiename,"",-10);
   
   if(json.length>0){
      var _db=JSON.stringify(json);
    setCookie(cookiename,_db,1);
   } 
 }  
 
//写入cookie
 function setCookie(c_name, value, expiredays){
  　　　var exdate=new Date();
  　　　exdate.setDate(exdate.getDate() + expiredays);
  　　　document.cookie=c_name+ "=" + escape(value) +";path=/;domain="+document.domain+";"+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
 }
//读取cookie   
 function getCookie(c_name){
  　　　　if (document.cookie.length>0){　　//先查询cookie是否为空，为空就return ""
  　　　　　　c_start=document.cookie.indexOf(c_name + "=")　　//通过String对象的indexOf()来检查这个cookie是否存在，不存在就为 -1　　
  　　　　　　if (c_start!=-1){ 
  　　　　　　　　c_start=c_start + c_name.length+1　　//最后这个+1其实就是表示"="号啦，这样就获取到了cookie值的开始位置
  　　　　　　　　c_end=document.cookie.indexOf(";",c_start)　　//其实我刚看见indexOf()第二个参数的时候猛然有点晕，后来想起来表示指定的开始索引的位置...这句是为了得到值的结束位置。因为需要考虑是否是最后一项，所以通过";"号是否存在来判断
  　　　　　　　　if (c_end==-1) c_end=document.cookie.length
  　　　　　　　　return unescape(document.cookie.substring(c_start,c_end))　　//通过substring()得到了值。想了解unescape()得先知道escape()是做什么的，都是很重要的基础，想了解的可以搜索下，在文章结尾处也会进行讲解cookie编码细节
  　　　　　　} 
  　　　　}
  　　　　return ""
 }

//关闭弹窗
function close_win(){
      $('.sg_nrk').animate({'top':'-500px' }, 300, function () {

        $('.sg_wszl').fadeOut('300');
      });
}
  /*------弹出滑动窗口--------*/
 $(function () {

        $('#activator').click(function () {

            $('.sg_wszl').fadeIn('300',function () {

                $('.sg_nrk').animate({'top':'50px' }, 300);

            });

        });

        $('.fzccx').click(function () {

            $('.sg_nrk').animate({'top':'-500' }, 300, function () {

                $('.sg_wszl').fadeOut('300');

            });

        });

    });
</script>
</block>


